In [43]:
tty
/dev/pts/1

PS

Process in this terminal

In [2]:
ps
  PID TTY          TIME CMD
14009 pts/1    00:00:00 bash
14310 pts/1    00:00:00 ps
In [4]:
ps -f 4180
UID        PID  PPID  C STIME TTY      STAT   TIME CMD
milad     4180  4175  0 14:23 tty1     Sl     2:06 qbittorrent
In [13]:
# get all process
ps -A | head -5 # same as -e
  PID TTY          TIME CMD
    1 ?        00:00:02 systemd
    2 ?        00:00:00 kthreadd
    3 ?        00:00:00 ksoftirqd/0
    5 ?        00:00:00 kworker/0:0H
In [45]:
ps aux | head -4
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.1 119720  5816 ?        Ss   Dec27   0:02 /sbin/init
root         2  0.0  0.0      0     0 ?        S    Dec27   0:00 [kthreadd]
root         3  0.0  0.0      0     0 ?        S    Dec27   0:01 [ksoftirqd/0]
In [60]:
ps axo comm,pid,uid,user,nice | head -4
COMMAND           PID   UID USER      NI
systemd             1     0 root       0
kthreadd            2     0 root       0
ksoftirqd/0         3     0 root       0
In [ ]:
# -ef same as ps aux
# -e or -A => all
# -f => full format
In [80]:
ps -ef | head -4
UID        PID  PPID  C STIME TTY          TIME CMD
root         1     0  0 Dec27 ?        00:00:02 /sbin/init
root         2     0  0 Dec27 ?        00:00:00 [kthreadd]
root         3     2  0 Dec27 ?        00:00:01 [ksoftirqd/0]
In [82]:
ps -u 1000 -o comm,pid,uid,user,ruser,nice,ppid,tty,group | head -4 # -u can be username
COMMAND           PID   UID USER     RUSER     NI  PPID TT       GROUP
tumblerd          307  1000 milad    milad     19     1 ?        milad
ps                326  1000 milad    milad      0 14009 pts/1    milad
bash              327  1000 milad    milad      0 14009 pts/1    milad
In [86]:
ps -eo comm,pid,uid,user,ruser,nice,ppid,tty,group | head -4
COMMAND           PID   UID USER     RUSER     NI  PPID TT       GROUP
systemd             1     0 root     root       0     0 ?        root
kthreadd            2     0 root     root       0     0 ?        root
ksoftirqd/0         3     0 root     root       0     2 ?        root
In [102]:
ps -ft pts/0
UID        PID  PPID  C STIME TTY          TIME CMD
milad    10420 10415  0 Dec27 pts/0    00:00:00 bash
milad    13626 10420  0 Dec27 pts/0    00:00:13 /usr/bin/python3 /home/milad/.lo
In [118]:
ps -ef | grep tint2
milad      544 14009  0 08:38 pts/1    00:00:00 grep --color=auto tint2
milad     1666     1  0 Dec27 tty1     00:00:49 tint2

pgrep

In [39]:
pgrep clementine
10985
10989
10990
10991
10992
In [22]:
pgrep vi -l
1632 xf86-video-inte
7075 dconf-service
In [33]:
pgrep -u root -l | head -5
1 systemd
2 kthreadd
3 ksoftirqd/0
5 kworker/0:0H
7 rcu_sched
In [35]:
pgrep -u root -vl | head -5
894 systemd-timesyn
998 atd
1010 avahi-daemon
1014 dbus-daemon
1016 avahi-daemon
In [38]:
pgrep -x vi
pgrep -x clementine -l
10985 clementine
In [41]:
pgrep -n clem -l
10992 clementine-tagr
In [120]:
pgrep -t tty1 -l -u root
1410 login
1632 xf86-video-inte
In [7]:
pgrep -t tty1 -a -u milad | head
1584 -bash
1597 /bin/sh /usr/bin/startx
1620 xinit /home/milad/.xinitrc -- /etc/X11/xinit/xserverrc :0 vt1 -keeptty -auth /tmp/serverauth.sKkqdc4rNQ
1621 /usr/lib/xorg/Xorg -nolisten tcp :0 vt1 -keeptty -auth /tmp/serverauth.sKkqdc4rNQ
1632 /usr/bin/openbox --startup /usr/lib/x86_64-linux-gnu/openbox-autostart OPENBOX
1636 dbus-launch --sh-syntax --exit-with-session ssh-agent openbox-session
1661 tint2
1664 pasystray
1667 clipit
1670 xxkb
In [6]:
pgrep -av pasystray > /dev/null # reverse

pidof

In [128]:
pidof bash
28742 28715 28668 27449 14009 10565 10420 1586
In [129]:
pidof -s bash
28742

Signals, kill, pkill

In [42]:
kill -l
 1) SIGHUP	 2) SIGINT	 3) SIGQUIT	 4) SIGILL	 5) SIGTRAP
 6) SIGABRT	 7) SIGBUS	 8) SIGFPE	 9) SIGKILL	10) SIGUSR1
11) SIGSEGV	12) SIGUSR2	13) SIGPIPE	14) SIGALRM	15) SIGTERM
16) SIGSTKFLT	17) SIGCHLD	18) SIGCONT	19) SIGSTOP	20) SIGTSTP
21) SIGTTIN	22) SIGTTOU	23) SIGURG	24) SIGXCPU	25) SIGXFSZ
26) SIGVTALRM	27) SIGPROF	28) SIGWINCH	29) SIGIO	30) SIGPWR
31) SIGSYS	34) SIGRTMIN	35) SIGRTMIN+1	36) SIGRTMIN+2	37) SIGRTMIN+3
38) SIGRTMIN+4	39) SIGRTMIN+5	40) SIGRTMIN+6	41) SIGRTMIN+7	42) SIGRTMIN+8
43) SIGRTMIN+9	44) SIGRTMIN+10	45) SIGRTMIN+11	46) SIGRTMIN+12	47) SIGRTMIN+13
48) SIGRTMIN+14	49) SIGRTMIN+15	50) SIGRTMAX-14	51) SIGRTMAX-13	52) SIGRTMAX-12
53) SIGRTMAX-11	54) SIGRTMAX-10	55) SIGRTMAX-9	56) SIGRTMAX-8	57) SIGRTMAX-7
58) SIGRTMAX-6	59) SIGRTMAX-5	60) SIGRTMAX-4	61) SIGRTMAX-3	62) SIGRTMAX-2
63) SIGRTMAX-1	64) SIGRTMAX	
1 : sighub, connection to terminal hangedup 2 : sigint, keyboard interrupt same as ctrl+c 15: sigterm, Default kill signal, terminate cleanly 9 : sigkill, Kill the process immediately 17: sigchld, Make zombies process 1 child 18: sigcont, coninue 19: sigstop, stop the process same as ctrl+z 20: sigtstp, stop wich can not be ignored
In [ ]:
# options are same as pgrep -n -P -u etc.
pkill -SIGTERM -u milad -x vi
In [ ]:
kill -2 1080

Jobs

bg, fg, &, jobs, ctrl+z, ctrl+c


Lecture notes

License

Creative Commons License

Linux Notes by Milad As (Ravexina) is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.


ravexina's gitlab

ravexina's github